home *** CD-ROM | disk | FTP | other *** search
- /*
- Blob Manager Demonstration: States and Capitals module
-
- This module is an example of an extremely simple interrogative
- scenario. The original thirteen colonies of the United States must
- be matched with their capital cities. There is a single button that
- says "Give Up?" If the user clicks the button, the answer is shown,
- the button's title changes to "Resume", and the scenario is frozen
- until the button is clicked. Then the answer is cleared, the capitals
- are shuffled, and the user may start over.
-
- If the correct answers are all gotten, the button again changes to
- "Resume" and the scenario is frozen until the button is clicked.
-
- The module is unexciting; it's meant as a basic illustration, rather
- than anything useful. There are lots of bells and whistles that
- could be added.
-
- 26 July 1986 Paul DuBois
- */
-
-
- # include "BlobDemo.h"
- # include <ControlMgr.h>
-
-
- # define nStates 13
-
- # define hState1 220
- # define hState2 110
- # define vState 16
- # define stateXOff 10
- # define stateYOff 5
- # define hCapital 85
- # define vCapital 16
- # define capXOff 225
- # define capYOff 5
-
-
- struct info
- {
- char *stateName;
- char *capName;
- };
-
-
-
- static GrafPtr statesPort;
- static BlobSetHandle donors; /* donor blobs */
- static BlobSetHandle receptors; /* receptor blobs */
- static ControlHandle giveUp;
- static Boolean paused = false;
-
- static struct info scPair[nStates] =
- {
- { "\pConnecticut", "\pHartford" },
- { "\pDelaware", "\pDover" },
- { "\pGeorgia", "\pAtlanta" },
- { "\pMaryland", "\pAnnapolis" },
- { "\pMassachusetts", "\pBoston" },
- { "\pNew Hampshire", "\pConcord" },
- { "\pNew Jersey", "\pTrenton" },
- { "\pNorth Carolina", "\pRaleigh" },
- { "\pNew York", "\pAlbany" },
- { "\pPennsylvania", "\pHarrisburg" },
- { "\pRhode Island", "\pProvidence" },
- { "\pSouth Carolina", "\pColumbia" },
- { "\pVirginia", "\pRichmond" }
- };
-
-
- static Activate (active)
- Boolean active;
- {
- if (active)
- {
- SetDragRects (statesPort);
- SetBCPermissions (true, true, false, true, true);
- }
- }
-
-
- static Update ()
- {
- DrawControls (statesPort);
- DrawBlobSet (receptors);
- DrawBlobSet (donors);
- }
-
-
- static Mouse (pt, t, mods)
- Point pt;
- long t;
- int mods;
- {
- BlobHandle b, d;
- ControlHandle ctl;
-
- if (FindControl (pt, statesPort, &ctl))
- {
- if (TrackControl (ctl, pt, nil))
- {
- if (paused) /* either all answers are correct, or we're */
- { /* showing the answer. Either way, restore */
- ThawBlobSet (receptors); /* to start state */
- ThawBlobSet (donors);
- ZUnglueGlobSet (receptors);
- ShuffleBlobSet (receptors);
- ShuffleBlobSet (donors);
- SetCTitle (giveUp, "\pGive Up?");
- ValidRect (&statesPort->portRect);
- paused = false;
- }
- else /* user gives up - show answer */
- {
- for (b = FirstBlob (receptors); b != nil; b = NextBlob (b))
- ZGlueGlob (FirstBMatch (b), b);
- FreezeBlobSet (receptors);
- FreezeBlobSet (donors);
- SetCTitle (giveUp, "\pResume");
- paused = true;
- }
- }
- }
- else
- {
- BlobClick (pt, t, donors, receptors);
- if (!paused && BlobSetQuiet (receptors)) /* answers correct? */
- {
- FreezeBlobSet (receptors);
- FreezeBlobSet (donors);
- SetCTitle (giveUp, "\pResume");
- paused = true;
- }
- }
- }
-
-
- /*
- Make blobs
- */
-
-
- MakeBlobs ()
- {
- int i;
- Rect r, r2;
- BlobHandle b1, b2;
-
- donors = NewBlobSet ();
- receptors = NewBlobSet ();
- for (i = 0; i < nStates; ++i)
- {
- b1 = NewBlob (donors, false, 1, false, 0L);
- b2 = NewBlob (receptors, false, 0, true, 0L);
- NewBlobMatch (b1, b2); /* attach the answer */
-
- OpenBlob (); /* draw donor blob */
- SetRect (&r, 0, 0, hCapital, vCapital);
- TextBox (&scPair[i].capName[1], (long) scPair[i].capName[0], &r, 1);
- CloseRectBlob (b1, &r, &r);
- MoveBlob (b1, inFullBlob, capXOff, capYOff + (vCapital + 1) * i);
-
- OpenBlob ();
- SetRect (&r, 0, 0, hState1, vState);
- SetRect (&r2, 0, 0, hState2, vState);
- TextBox (&scPair[i].stateName[1], (long) scPair[i].stateName[0], &r2, 1);
- SetRect (&r2, 0, 0, hCapital, vCapital);
- OffsetRect (&r2, hState2 + 5, 0);
- EraseRect (&r2);
- FrameRect (&r2);
- CloseRectBlob (b2, &r2, &r);
- MoveBlob (b2, inFullBlob, stateXOff, stateYOff + (vState + 2) * i);
- }
- ShuffleBlobSet (donors);
- EnableBlobSet (receptors);
- EnableBlobSet (donors);
- }
-
-
- StatesInit ()
- {
- Rect r;
-
- SkelWindow (statesPort = GetDemoWind (statesWindRes),
- Mouse, /* mouse clicks */
- nil, /* key clicks */
- Update, /* updates */
- Activate, /* activate/deactivate events */
- nil, /* close window */
- DoWClobber, /* dispose of window */
- nil, /* idle proc */
- false); /* irrelevant, since no idle proc */
-
- /*
- Make blobs. Generally have to make donors before receptors.
- */
- MakeBlobs ();
-
- r = statesPort->portRect;
- SetRect (&r, r.left + 5, r.bottom - 25, r.left + 75, r.bottom - 5);
- giveUp = NewControl (statesPort, &r, "\pGive Up?", true, 0, 0, 0,
- pushButProc, nil);
-
- Update ();
- ValidRect (&statesPort->portRect);
- }
-